Homework 1: Bird database
This homework gives pracice with the most important aspects of SQL we covered.
Assignment
Write commands to implement the database represented in the class diagram below in SQLite. You can use this SQL interpreter or a local installation of SQLite, at your discretion. You will be submitting all of the SQL commands to implement the database, as described below.
Database design

Implement the database as pictured above. Note that the many-to-many relationship between Species and Regions will require a junction table. Write the following in SQL (invent data as necessary).
- Create all tables
- Use a primary key for each table (a junction table should get a two-column primary key if each pairing should happen at most once)
- Declare foreign key constraints where appropriate (recall that you will want to issue the
PRAGMA foreign_keys = ON;
command before using foreign keys)
- Declare an index for the SpotterID foreign key column of Sightings
- Fill tables with initial data
- Put in at least 6 actual bird species
- Put in the regions: Midwest, Northeast, South, West
- Put in 3 spotters (one of them should be JD - the Math/CS department head who is a birder)
- Put in at least 4 sightings; at least two of them should be by JD
- Associate each bird with the regions it actually lives in
-
Include the following query commands:
- Select the lat, lon, date, and species name for each sighting made by JD.
- Pick some specific bird species and write a query that selects all region names in which it lives.
-
Include the following update command:
- Update some bird's name to its scientific name.
-
Include the following delete command:
- Delete a given spotter by ID and NULL out his/her ID in all of the associated sightings. Do this as a transaction and specify OR ROLLBACK for the UPDATE command therein. I would do the same for the DELETE command, but OR ROLLBACK is not supported for DELETE in Sqlite because foreign key constraints are not checked by Sqlite's OR ROLLBACK algorithm, and - as far as I can tell - none of the other checks performed are relevant to DELETE.
Note that in real life, it would likely be useful to have a geospatial index on latitude and longitude. SQLite doesn't support this, but there are add-ons and workarounds (though that is not required for this assignment).
Submit a text document with all of your SQL commands in Educat, by November 13, 2024.